<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改短链接系统设置')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-config-edit" th:object="${shortConfig}">
            <input name="key" th:field="*{key}" type="hidden">
            
            <div class="form-group" th:if="*{type=='caption'}">  
            	<input name="value" id="realValue" class="form-control" type="hidden">  
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input name="value_title" id="value_title" class="form-control" type="text">
                </div>
            </div>
            
            <div class="form-group">    
                <label class="col-sm-3 control-label">配置值：</label>
                <div class="col-sm-8" th:if="*{type=='text'}">
                    <input name="value" th:field="*{value}" class="form-control" type="text">
                </div>
                <div class="col-sm-8" th:if="*{type=='caption'}">
                	<textarea rows="8" cols="" name="value_content" id="value_content" class="form-control"></textarea>
                </div>
                <div class="col-sm-8" th:if="*{type=='select-frame'}">
                    <select name="value" class="form-control" required>
                    	<option value="FRAME" th:selected="*{value=='FRAME'}">框架frame</option>
                    	<option value="FORWARD" th:selected="*{value=='FORWARD'}">转发forward</option>
                    </select>
                </div>
                
                <div class="col-sm-8" th:if="*{type=='yes-no'}">
                    <select name="value" class="form-control" required>
                    	<option value="TRUE" th:selected="*{value=='TRUE'}">开启</option>
                    	<option value="FALSE" th:selected="*{value=='FALSE'}">关闭</option>
                    </select>
                </div>
                
                <div class="col-sm-4" th:if="*{type=='number-size' || type=='number-day'}">
                    <input min="-1" name="value" th:field="*{value}" class="form-control" type="number" required>
                </div>
                <label th:if="*{type=='number-day'}" style="text-align:left" class="col-sm-4 control-label">天</label>
            	<label th:if="*{type=='number-size'}" style="text-align:left" class="col-sm-4 control-label">条</label>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">描述：</label>
                <div class="col-sm-8">
                    <input name="des" th:field="*{des}" class="form-control" type="text" disabled="disabled">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
    	var type = [[${shortConfig.type}]];
    	var value = [[${shortConfig.value}]];
    	if(type=='caption' && value!=null && value!=''){
    		var strs = value.split("@||@")
    		if(strs.length==1){
    			$("#value_content").val(strs[0]);
    		}
    		if(strs.length==2){
    			$("#value_title").val(strs[0]);
    			$("#value_content").val(strs[1]);
    		}
    	}
    	
        var prefix = ctx + "short/config";
        $("#form-config-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
            	if(type=='caption'){
            		$("#realValue").val($("#value_title").val()+"@||@"+$("#value_content").val());
            	}
                $.operate.save(prefix + "/edit", $('#form-config-edit').serialize());
            }
        }
    </script>
</body>
</html>